<!DOCTYPE HTML>
<html>
<head>
<title>EnvSet | AutoHotkey</title>
<meta name="description" content="The EnvSet command writes a value to a variable contained in the environment." />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>EnvSet</h1>

<p>将值写入环境包含的<a href="../Variables.htm">变量</a>中.</p>

<pre class="Syntax"><span class="func">EnvSet</span>, EnvVar, Value</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>EnvVar</dt>
  <dd>要使用的<a href="../Concepts.htm#environment-variables">环境变量</a>的名称, 例如 "COMSPEC" 或 "PATH".</dd>

  <dt>Value</dt>
  <dd><p>要设置到目标<a href="../Concepts.htm#environment-variables">环境变量</a>的值.</p></dd>

</dl>
<h2 id="Error_Handling">错误处理</h2>
<p><span class="ver">[v1.1.04+]</span>: 此命令失败时会抛出异常. 想了解更多信息, 请参阅<a href="Catch.htm#RuntimeErrors">运行时错误</a>.</p>
<p>如果遇到问题则 <a href="../misc/ErrorLevel.htm">ErrorLevel</a> 被置为 1, 否则为 0.</p>
<h3>备注</h3>
<p>操作系统限制每个环境变量的文本最多为 32 KB.</p>
<p>此命令创建或改变的环境变量只有由此脚本通过 <a href="Run.htm">Run</a> 或 <a href="Run.htm">RunWait</a> 运行的程序才可以读取. 请参阅<a href="../Concepts.htm#environment-variables">环境变量</a>了解更多细节.</p>
<p>此命令与 <a href="SetEnv.htm">SetEnv</a> 分别存在, 因为<a href="../Variables.htm">普通脚本变量</a>没有存储在环境中. 这是由于性能会变差且操作系统限制环境变量大小在 32 KB 之内.</p>
<h3 id="Related">相关</h3>
<p><a href="EnvGet.htm">EnvGet</a>, <a href="_NoEnv.htm">#NoEnv</a>, <a href="../Concepts.htm#environment-variables">环境变量</a>, <a href="EnvUpdate.htm">EnvUpdate</a>, <a href="SetEnv.htm">SetEnv</a>, <a href="Run.htm">Run</a>, <a href="Run.htm">RunWait</a></p>
<h3>示例</h3>
<div class="ex" id="ExBasic">
<p><a class="ex_number" href="#ExBasic"></a> 将一些文字写入环境中的 AutGUI 变量中.</p>
<pre>EnvSet, AutGUI, Some text to put in the variable.</pre>
</div>

</body>
</html>